package com.dimples.dd.system.convert;

import com.dimples.dd.common.pojo.PageResult;
import com.dimples.dd.system.model.entity.Oauth2RegisteredClientDO;
import com.dimples.dd.system.model.form.OAuth2ClientForm;
import com.dimples.dd.system.model.vo.OAuth2ClientPageVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2024/8/8
 */
@Mapper(componentModel = "spring")
public interface Oauth2RegisteredClientConvert {

    @Mapping(target = "authorizationGrantTypes", expression = "java(cn.hutool.core.util.StrUtil.join(cn.hutool.core.util.StrUtil.COMMA, oAuth2ClientForm.getAuthorizationGrantTypes()))")
    @Mapping(target = "scopes", expression = "java(cn.hutool.core.util.StrUtil.join(cn.hutool.core.util.StrUtil.COMMA, oAuth2ClientForm.getScopes()))")
    Oauth2RegisteredClientDO form2Entity(OAuth2ClientForm oAuth2ClientForm);

    @Mapping(target = "authorizationGrantTypes", expression = "java(cn.hutool.core.util.StrUtil.split(client.getAuthorizationGrantTypes(), cn.hutool.core.util.StrUtil.COMMA))")
    @Mapping(target = "scopes", expression = "java(cn.hutool.core.util.StrUtil.split(client.getScopes(), cn.hutool.core.util.StrUtil.COMMA))")
    OAuth2ClientForm entity2Form(Oauth2RegisteredClientDO client);

    PageResult<OAuth2ClientPageVO> entity2Page(PageResult<Oauth2RegisteredClientDO> pageResult);

    @Mapping(target = "authorizationGrantTypes", expression = "java(cn.hutool.core.util.StrUtil.split(client.getAuthorizationGrantTypes(), cn.hutool.core.util.StrUtil.COMMA))")
    @Mapping(target = "scopes", expression = "java(cn.hutool.core.util.StrUtil.split(client.getScopes(), cn.hutool.core.util.StrUtil.COMMA))")
    OAuth2ClientPageVO entity2Vo(Oauth2RegisteredClientDO client);
}

